import { KoaMiddlewareInterface} from "routing-controllers";
import { Service,Inject } from "typedi";
import jwt from "../utils/jwt";
import {config} from '../config'

@Service()
export default class TokenLoginMiddlewares implements KoaMiddlewareInterface {

    use(context: any, next: (err?: any) => Promise<any>): any {
      let token = context.request.header.token
      if(!token || token=='' ||!jwt.verifyToken(token)){
            context.response.message = 'token验证失败';
            context.redirect(`${config.apiurl}/v1/home/isLoginDelete`);

      }else{
        return next()
      }
    
      }
}
